package com.sgcc.pda.web.binder;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.RemoteException;
import android.text.TextUtils;

import com.sgcc.pda.baselibrary.utils.LogUtil;
import com.sgcc.pda.common.aidl.CommonCallback;
import com.sgcc.pda.common.aidl.CommonParams;
import com.sgcc.pda.common.aidl.CommonResults;
import com.sgcc.pda.sdk.utils.db.SharepreferenceUtil;
import com.sgcc.pda.web.WebConstant;
import com.sgcc.pda.sdk.utils.DataConversionUtil;
import com.sgcc.pda.web.IHttpCallbackInterface;
import com.sgcc.pda.web.IWebManager;

import org.json.JSONException;
import org.json.JSONObject;

import java.lang.reflect.Method;

/**
 * 上行通信服务web基础服务接口-封装给插件APP通过Binder调用
 *
 * @author Ben
 * @date 2019/06/12
 */
public class WebBinderUtil {
    private static final String TAG = "WebBinderUtil";
    private static final String BROADCAST_NAME="broadcastName";
    private static final String METHOD_NAME="methodName";
    private static final String REQUEST_PARAMS="requestParams";
    private static final String SUCCESS="success";
    private static final String SERVER_NAME="serverName";
    private static final String FILE_ID="fileId";
    private static final String FILE_NAME="fileName";
    private static final String APP_NO="app_no";
    private static final String APP_TYPE="app_type";
    private static final String FILE_PATHS="filePaths";
    private static final String IMAGES="images";
    private static final String RESULT_JSON="resultJson";
    // 接口类名
    static final String CLASS_NAME = "com.sgcc.pda.web.binder.WebBinderUtil";

    private IWebManager mService = null;
    private boolean isBind = false;
    private Context mContext;

    private ServiceConnection mConnection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            mService = IWebManager.Stub.asInterface(service);
            isBind = true;
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            isBind = false;
            mService = null;
        }
    };

    private WebBinderUtil() {
    }

    private static class Instance {
        private static final WebBinderUtil mInstance = new WebBinderUtil();
    }

    /**
     * 单例
     */
    public static WebBinderUtil getInstance() {
        return Instance.mInstance;
    }

    /**
     * 绑定掌机基础服务提供接口的AIDL服务
     *
     * @param context
     * @return 是否绑定
     */
    public boolean bind(Context context) {
        mContext = context;
        if (isBind) {
            return isBind;
        }
        Intent intent = new Intent("com.sgcc.pda.web.AIDL_WEB_SERVICE");
        intent.setPackage("com.sgcc.pda.mdrh.task.safe");
        try {
            isBind = context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
        } catch (Exception e) {
            e.printStackTrace();
            isBind = false;
        }
        return isBind;
    }

    /**
     * 取消绑定掌机基础服务提供接口的AIDL服务
     *
     * @param context
     * @return 是否绑定
     */
    public void unbind(Context context) {
        try {
            context.unbindService(mConnection);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 根据方法名执行对应的方法
     *
     * @param params   参数
     * @param callback 回调
     * @return 结果
     */
    public CommonResults execute(CommonParams params, CommonCallback callback) {
        String methodName = params.getMethodName();
        try {
            // 通过反射调用方法，方法参数与返回值必须统一成(CommonParams，CommonCallback，CommonResults）
            Method method = getClass().getMethod(methodName, CommonParams.class, CommonCallback.class);
            return (CommonResults) method.invoke(this, params, callback);
        } catch (Exception e) {
            e.printStackTrace();
            return new CommonResults("-2", e.getMessage());
        }
    }

    /**
     * 访问网络协议(已过时，请使用postDataCallback)
     *
     * @param params 接口参数 :
     *               broadcastName  获取结果广播名称
     *               methodName     请求方法名
     *               requestParams  请求参数——json格式
     * @return code 1 成功 其它失败
     */
    @Deprecated
    public CommonResults postData(CommonParams params, CommonCallback callback) throws RemoteException {
        String broadcastName = params.getString(BROADCAST_NAME);
        String methodName = params.getString(METHOD_NAME);
        String requestParams = params.getString(REQUEST_PARAMS);

        mService.postData(broadcastName, methodName, requestParams);
        return new CommonResults("1", SUCCESS);
    }

    /**
     * 访问自定义的url （已过时）
     *
     * @param params 接口参数 :
     *               broadcastName 获取结果广播名称
     *               url 访问的地址
     * @return code 1 成功 其它失败
     */
    @Deprecated
    public CommonResults requestCustomerUrl(CommonParams params, CommonCallback callback) throws RemoteException {
        String broadcastName = params.getString(BROADCAST_NAME);
        String url = params.getString("url");

        mService.requestCustomerUrl(broadcastName, url);
        return new CommonResults("1", SUCCESS);
    }

    /**
     * 下载文件-使用老的前置下载方式（已过时）
     *
     * @param params 接口参数 :
     *               type           0不使用进度参数  1使用进度参数
     *               broadcastName  获取结果广播名称
     *               serverName     xx
     *               functionName   xx
     *               fileId         xx
     *               fileName       xx
     * @return code 1 成功 其它失败
     */
    @Deprecated
    public CommonResults downloadComm(CommonParams params, CommonCallback callback) throws RemoteException {
        int type = params.getInt("type");
        String broadcastName = params.getString(BROADCAST_NAME);
        String serverName = params.getString(SERVER_NAME);
        String functionName = params.getString("functionName");
        String fileId = params.getString(FILE_ID);
        String fileName = params.getString(FILE_NAME);

        mService.downloadComm(type, broadcastName, serverName, functionName, fileId, fileName);
        return new CommonResults("1", SUCCESS);
    }

    /**
     * 下载文件-直接路径下载（已过时）
     *
     * @param params 接口参数 :
     *               broadcastName  获取结果广播名称
     *               filePath       文件路径
     * @return code 1 成功 其它失败
     */
    @Deprecated
    public CommonResults downloadFile(CommonParams params, CommonCallback callback) throws RemoteException {
        String broadcastName = params.getString(BROADCAST_NAME);
        String fileUrl = params.getString("fileUrl");
        String filePath = params.getString("filePath");

        mService.downloadFile(broadcastName, fileUrl, filePath);
        return new CommonResults("1", SUCCESS);
    }

    /**
     * 下载文件-使用老的前置下载方式（已过时）
     *
     * @param params 接口参数 :
     *               broadcastName  获取结果广播名称
     *               type           0不适用进度参数  1使用进度参数
     *               serverName     xx
     *               fileId         xx
     *               fileName       xx
     * @return code 1 成功 其它失败
     */
    @Deprecated
    public CommonResults downloadFile2(CommonParams params, CommonCallback callback) throws RemoteException {
        String broadcastName = params.getString(BROADCAST_NAME);
        int type = params.getInt("type");
        String serverName = params.getString(SERVER_NAME);
        String fileId = params.getString(FILE_ID);
        String fileName = params.getString(FILE_NAME);

        mService.downloadFile2(broadcastName, type, serverName, fileId, fileName);
        return new CommonResults("1", SUCCESS);
    }

    /**
     * 上传照片 多图使用;号进行分割,imgs和filePahts 暂时都传递文件路径（已过时）
     *
     * @param params 接口参数 :
     *               broadcastName  广播名称
     *               app_no         工单号
     *               app_type       工单类型
     *               imgs           照片信息(多数据集)
     *               filePaths      文件路径(多数据集)
     * @return code 1 成功 其它失败
     */
    @Deprecated
    public CommonResults upFileImg(CommonParams params, CommonCallback callback) throws RemoteException {
        String broadcastName = params.getString(BROADCAST_NAME);
        String app_no = params.getString(APP_NO);
        String app_type = params.getString(APP_TYPE);
        String imgs = params.getString("imgs");
        String filePaths = params.getString(FILE_PATHS);

        mService.upFileImg(broadcastName, app_no, app_type, imgs, filePaths);
        return new CommonResults("1", SUCCESS);
    }

    /**
     * 取消http访问（已过时）
     *
     * @param params 接口参数 :
     *               broadcastName  获取结果广播名称
     * @return code 1 成功 其它失败
     */
    @Deprecated
    public CommonResults cancel(CommonParams params, CommonCallback callback) throws RemoteException {
        String broadcastName = params.getString(BROADCAST_NAME);

        mService.cancle(broadcastName);
        return new CommonResults("1", SUCCESS);
    }

    /**
     * 子应用登录（已过时）
     *
     * @param params 接口参数 :
     *               broadcastName  获取结果广播名称
     * @return code 1 成功 其它失败
     */
    @Deprecated
    public CommonResults getLoginHandsetDate(CommonParams params, CommonCallback callback) throws RemoteException {
        String broadcastName = params.getString(BROADCAST_NAME);

        mService.getLoginHandsetDate(broadcastName);
        return new CommonResults("1", SUCCESS);
    }

    /**
     * 子应用登录注销（已过时）
     *
     * @param params 接口参数 :
     *               broadcastName  获取结果广播名称
     * @return code 1 成功 其它失败
     */
    @Deprecated
    public CommonResults logout(CommonParams params, CommonCallback callback) throws RemoteException {
        String broadcastName = params.getString(BROADCAST_NAME);

        mService.logout(broadcastName);
        return new CommonResults("1", SUCCESS);
    }

    /**
     * xx（已过时）
     *
     * @param params 接口参数 :
     *               broadcastName  获取结果广播名称
     *               app_no         xx
     *               app_type       xx
     *               imgs           xx
     *               filePaths      xx
     * @return code 1 成功 其它失败
     */
    @Deprecated
    public CommonResults upFileImg2(CommonParams params, CommonCallback callback) throws RemoteException {
        String broadcastName = params.getString(BROADCAST_NAME);
        String app_no = params.getString(APP_NO);
        String app_type = params.getString(APP_TYPE);
        String imgs = params.getString("imgs");
        String filePaths = params.getString(FILE_PATHS);

        mService.upFileImg2(broadcastName, app_no, app_type, imgs, filePaths);
        return new CommonResults("1", SUCCESS);
    }

    /**
     * xx（已过时）
     *
     * @param params 接口参数 :
     *               broadcastName  获取结果广播名称
     *               meetingId      xx
     *               orderIds       xx
     *               filePaths      xx
     * @return code 1 成功 其它失败
     */
    @Deprecated
    public CommonResults saveGQH(CommonParams params, CommonCallback callback) throws RemoteException {
        String broadcastName = params.getString(BROADCAST_NAME);
        String meetingId = params.getString("meetingId");
        String orderIds = params.getString("orderIds");
        String filePaths = params.getString(FILE_PATHS);

        mService.saveGQH(broadcastName, meetingId, orderIds, filePaths);
        return new CommonResults("1", SUCCESS);
    }

    /**
     * xx（已过时）
     *
     * @param params 接口参数 :
     *               broadcastName          获取结果广播名称
     *               assetNo                xx
     *               deviceType             xx
     *               oldModuleNum           xx
     *               oldModuleTypeNo        xx
     *               oldModuleFactoryName   xx
     *               newModuleTypeNo        xx
     *               newModuleFactoryNo     xx
     *               newModuleFactoryName   xx
     *               newModuleNum           xx
     *               reason                 xx
     *               images                 xx
     *               testResult             xx
     *               operUSERNO             xx
     *               operDT                 xx
     * @return code 1 成功 其它失败
     */
    @Deprecated
    public CommonResults setModuleInfo(CommonParams params, CommonCallback callback) throws RemoteException {
        String broadcastName = params.getString(BROADCAST_NAME);
        String assetNo = params.getString("assetNo");
        String deviceType = params.getString("deviceType");
        String oldModuleNum = params.getString("oldModuleNum");
        String oldModuleTypeNo = params.getString("oldModuleTypeNo");
        String oldModuleFactoryName = params.getString("oldModuleFactoryName");
        String newModuleTypeNo = params.getString("newModuleTypeNo");
        String newModuleFactoryNo = params.getString("newModuleFactoryNo");
        String newModuleFactoryName = params.getString("newModuleFactoryName");
        String newModuleNum = params.getString("newModuleNum");
        String reason = params.getString("reason");
        String images = params.getString(IMAGES);
        String testResult = params.getString("testResult");
        String operUSERNO = params.getString("operUSERNO");
        String operDT = params.getString("operDT");

        mService.setModuleInfo(broadcastName, assetNo, deviceType, oldModuleNum, oldModuleTypeNo,
                oldModuleFactoryName, newModuleTypeNo, newModuleFactoryNo, newModuleFactoryName,
                newModuleNum, reason, images, testResult, operUSERNO, operDT);

        return new CommonResults("1", SUCCESS);
    }

    /**
     * xx（已过时）
     *
     * @param params 接口参数 :
     *               broadcastName          获取结果广播名称
     *               assetNo                xx
     *               deviceType             xx
     *               oldModuleNum           xx
     *               oldModuleTypeNo        xx
     *               oldModuleFactoryName   xx
     *               newModuleTypeNo        xx
     *               newModuleFactoryNo     xx
     *               newModuleFactoryName   xx
     *               newModuleNum           xx
     *               reason                 xx
     *               images                 xx
     *               testResult             xx
     *               operUSERNO             xx
     *               operDT                 xx
     * @return code 1 成功 其它失败
     */
    @Deprecated
    public CommonResults setModuleInfoNew(CommonParams params, CommonCallback callback) throws RemoteException {
        String broadcastName = params.getString(BROADCAST_NAME);
        String assetNo = params.getString("assetNo");
        String deviceType = params.getString("deviceType");
        String oldModuleNum = params.getString("oldModuleNum");
        String oldModuleTypeNo = params.getString("oldModuleTypeNo");
        String oldModuleFactoryName = params.getString("oldModuleFactoryName");
        String newModuleTypeNo = params.getString("newModuleTypeNo");
        String newModuleFactoryNo = params.getString("newModuleFactoryNo");
        String newModuleFactoryName = params.getString("newModuleFactoryName");
        String newModuleNum = params.getString("newModuleNum");
        String reason = params.getString("reason");
        String images = params.getString(IMAGES);
        String testResult = params.getString("testResult");
        String operUSERNO = params.getString("operUSERNO");
        String operDT = params.getString("operDT");

        mService.setModuleInfoNew(broadcastName, assetNo, deviceType, oldModuleNum, oldModuleTypeNo,
                oldModuleFactoryName, newModuleTypeNo, newModuleFactoryNo, newModuleFactoryName,
                newModuleNum, reason, images, testResult, operUSERNO, operDT);

        return new CommonResults("1", SUCCESS);
    }

    /**
     * xx（已过时）
     *
     * @param params 接口参数 :
     *               broadcastName  获取结果广播名称
     *               input          xx
     *               filePaths      xx
     * @return code 1 成功 其它失败
     */
    @Deprecated
    public CommonResults saveSBZC(CommonParams params, CommonCallback callback) throws RemoteException {
        String broadcastName = params.getString(BROADCAST_NAME);
        String input = params.getString("input");
        String filePaths = params.getString(FILE_PATHS);

        mService.saveSBZC(broadcastName, input, filePaths);
        return new CommonResults("1", SUCCESS);
    }

    /**
     * 上传图文（已过时）
     *
     * @param params 接口参数 :
     *               broadcastName  获取结果广播名称
     *               methodName     方法名
     *               serverName     服务名
     *               requestParams  参数
     *               images         图片
     * @return code 1 成功 其它失败
     */
    @Deprecated
    public CommonResults uploadPramsAndImages(CommonParams params, CommonCallback callback) throws RemoteException {
        String broadcastName = params.getString(BROADCAST_NAME);
        String methodName = params.getString(METHOD_NAME);
        String serverName = params.getString(SERVER_NAME);
        String requestParams = params.getString(REQUEST_PARAMS);
        String images = params.getString(IMAGES);

        mService.uploadPramsAndImages(broadcastName, methodName, serverName, requestParams, images);
        return new CommonResults("1", SUCCESS);
    }

    /**
     * 下载文件-使用老的前置下载方式（已过时）
     *
     * @param params 接口参数 :
     *               broadcastName  获取结果广播名称
     *               type           0不适用进度参数  1使用进度参数
     *               serverName     xx
     *               fileId         xx
     *               fileName       xx
     *               progress       xx
     *               isCancel       xx
     * @return code 1 成功 其它失败
     */
    @Deprecated
    public CommonResults downloadFile3(CommonParams params, CommonCallback callback) throws RemoteException {
        String broadcastName = params.getString(BROADCAST_NAME);
        int type = params.getInt("type");
        String serverName = params.getString(SERVER_NAME);
        String fileId = params.getString(FILE_ID);
        String fileName = params.getString(FILE_NAME);
        String progress = params.getString("progress");
        boolean isCancel = params.getBoolean("isCancel");

        mService.downloadFile3(broadcastName, type, serverName, fileId, fileName, progress, isCancel);

        return new CommonResults("1", SUCCESS);
    }

    /**
     * 下载文件-使用老的前置下载方式（已过时）
     *
     * @param params 接口参数 :
     *               broadcastName  获取结果广播名称
     *               requestParams       参数集合
     *               serverName     服务名称
     *               webMethod      下载服务端使用的方法名称
     * @return code 1 成功 其它失败
     */
    @Deprecated
    public CommonResults downloadFileReal(CommonParams params, CommonCallback callback) throws RemoteException {
        String broadcastName = params.getString(BROADCAST_NAME);
        String requestParams = params.getString(REQUEST_PARAMS);
        String serverName = params.getString(SERVER_NAME);
        String webMethod = params.getString("webMethod");

        mService.downloadFileReal(broadcastName, requestParams, serverName, webMethod);
        return new CommonResults("1", SUCCESS);
    }

    /**
     * 访问网络协议
     *
     * @param params   接口参数 :
     *                 class: com.sgcc.pda.web.binder.WebBinderUtil
     *                 method: postDataCallback
     *                 params:{
     *                 methodName: indicators/collectSucctRate
     *                 serverName:
     *                 requestParams: operId=540100000000303C&stateDate=20190709&orgNo=41401
     *                 }
     * @param callback 接口回调 : code 1 成功 其它失败
     *                 results(code==1):
     *                 0 : result 请求结果
     * @return code 1 成功 其它失败
     */
    public CommonResults postDataCallback(CommonParams params, final CommonCallback callback) throws RemoteException {
        String methodName = params.getString(METHOD_NAME);
        String serverName = params.getString(SERVER_NAME);
        String requestParams = params.getString(REQUEST_PARAMS);

        JSONObject jb = new JSONObject();
        try {
            jb.put("SERVER_NAME", serverName);
            LogUtil.i("请求参数：" + methodName + "?" + requestParams);
            String paramsHex = DataConversionUtil.str2HexStr(methodName + "?" + requestParams);//方法名？+参数（key=value&）
            jb.put("REQUEST_PARM", paramsHex);
            jb.put("UID", SharepreferenceUtil.getUid(mContext));
            jb.put("MAC", "12345");

        } catch (JSONException e) {
            e.printStackTrace();
        }
        mService.postDataCallback(WebConstant.COMM_FONT, jb.toString(), new IHttpCallbackInterface.Stub() {
            @Override
            public void onSuccess(String result) throws RemoteException {
                CommonResults results = new CommonResults("1", SUCCESS);
                results.addResult(RESULT_JSON, result);
                if (callback != null) {
                    callback.callback(results);
                }
            }

            @Override
            public void onFailed(int errorCode, String errorMsg) throws RemoteException {
                CommonResults results = new CommonResults("-" + errorCode, errorMsg);
                if (callback != null) {
                    callback.callback(results);
                }
            }
        });
        return new CommonResults("1", SUCCESS);
    }


    /**
     * 上传图文 无广播
     *
     * @param params   接口参数 :
     *                 methodName       方法名
     *                 serverName       服务名
     *                 requestParams    参数
     *                 images           图片
     * @param callback 接口回调 : code 1 成功 其它失败
     *                 results(code==1):
     *                 0 : result 请求结果
     * @return code 1 成功 其它失败
     */
    public CommonResults uploadPramsAndImagesNoBroadcast(CommonParams params, final CommonCallback callback) throws RemoteException {
        String methodName = params.getString(METHOD_NAME);
        String serverName = params.getString(SERVER_NAME);
        String requestParams = params.getString(REQUEST_PARAMS);
        String images = params.getString(IMAGES);

        mService.uploadPramsAndImagesNoBroadcast(methodName, serverName, requestParams, images, new IHttpCallbackInterface.Stub() {
            @Override
            public void onSuccess(String result) throws RemoteException {
                CommonResults results = new CommonResults("1", SUCCESS);
                results.addResult(RESULT_JSON, result);
                if (callback != null) {
                    callback.callback(results);
                }
            }

            @Override
            public void onFailed(int errorCode, String errorMsg) throws RemoteException {
                CommonResults results = new CommonResults("-" + errorCode, errorMsg);
                if (callback != null) {
                    callback.callback(results);
                }
            }
        });
        return new CommonResults("1", SUCCESS);
    }

    /**
     * 上传照片 多图使用;号进行分割,imgs和filePahts 暂时都传递文件路径
     * 无广播方式
     *
     * @param params   接口参数 :
     *                 app_no       工单号
     *                 app_type     工单类型
     *                 imgs         照片信息(多数据集)
     *                 filePaths    文件路径(多数据集)
     * @param callback 接口回调 : code 1 成功 其它失败
     *                 results(code==1):
     *                 0 : result 请求结果
     * @return code 1 成功 其它失败
     */
    public CommonResults upFileImgNoBroadcast(CommonParams params, final CommonCallback callback) throws RemoteException {
        String app_no = params.getString(APP_NO);
        String app_type = params.getString(APP_TYPE);
        String imgs = params.getString("imgs");
        String filePaths = params.getString(FILE_PATHS);

        mService.upFileImgNoBroadcast(app_no, app_type, imgs, filePaths, new IHttpCallbackInterface.Stub() {
            @Override
            public void onSuccess(String result) throws RemoteException {
                CommonResults results = new CommonResults("1", SUCCESS);
                results.addResult(RESULT_JSON, result);
                if (callback != null) {
                    callback.callback(results);
                }
            }

            @Override
            public void onFailed(int errorCode, String errorMsg) throws RemoteException {
                CommonResults results = new CommonResults("-" + errorCode, errorMsg);
                if (callback != null) {
                    callback.callback(results);
                }
            }
        });
        return new CommonResults("1", SUCCESS);
    }

    /**
     * 第三方厂家访问网络协议
     * 上行通讯服务获取uid
     *
     * @param params   接口参数 :
     *                 methodName     xx
     *                 requestParams  请求参数——json格式
     * @param callback 接口回调 : code 1 成功 其它失败
     *                 results(code==1):
     *                 0 : result 请求结果
     * @return code 1 成功 其它失败
     */
    public CommonResults otherPostDataCallback(CommonParams params, final CommonCallback callback) throws RemoteException {
        String methodName = params.getString(METHOD_NAME);
        String requestParams = params.getString(REQUEST_PARAMS);

        mService.otherPostDataCallback(methodName, requestParams, new IHttpCallbackInterface.Stub() {
            @Override
            public void onSuccess(String result) throws RemoteException {
                CommonResults results = new CommonResults("1", SUCCESS);
                results.addResult(RESULT_JSON, result);
                if (callback != null) {
                    callback.callback(results);
                }
            }

            @Override
            public void onFailed(int errorCode, String errorMsg) throws RemoteException {
                CommonResults results = new CommonResults("-" + errorCode, errorMsg);
                if (callback != null) {
                    callback.callback(results);
                }
            }
        });
        return new CommonResults("1", SUCCESS);
    }

    /**
     * 下载人脸相关文件-使用老的前置下载方式
     *
     * @param params 接口参数 :
     *               broadcastName  xx
     *               type           0不适用进度参数  1使用进度参数
     *               serverName     xx
     *               fileId         xx
     *               fileName       xx
     * @return code 1 成功 其它失败
     */
    public CommonResults downloadUpfileFile(CommonParams params, CommonCallback callback) throws RemoteException {
        String broadcastName = params.getString(BROADCAST_NAME);
        int type = params.getInt("type");
        String serverName = params.getString(SERVER_NAME);
        String fileId = params.getString(FILE_ID);
        String fileName = params.getString(FILE_NAME);

        mService.downloadUpfileFile(broadcastName, type, serverName, fileId, fileName);
        return new CommonResults("1", SUCCESS);
    }

    /**
     * 访问网络协议
     * 增加请求头方法
     *
     * @param params   接口参数 :
     *                 class: com.sgcc.pda.web.binder.WebBinderUtil
     *                 method: postDataCallback
     *                 params:{
     *                 methodName: indicators/collectSucctRate
     *                 serverName:
     *                 requestParams: operId=540100000000303C&stateDate=20190709&orgNo=41401
     *                 }
     * @param callback 接口回调 : code 1 成功 其它失败
     *                 results(code==1):
     *                 0 : result 请求结果
     * @return code 1 成功 其它失败
     */
    public CommonResults postHeaderDataCallback(CommonParams params, final CommonCallback callback) throws RemoteException {
        String methodName = params.getString(METHOD_NAME);
        String serverName = params.getString(SERVER_NAME);
        String header = params.getString("header");
        String requestParams = params.getString(REQUEST_PARAMS);

        JSONObject jb = new JSONObject();
        try {
            jb.put("SERVER_NAME", serverName);
            LogUtil.i("请求参数：" + methodName + "?" + requestParams);
            String paramsHex = DataConversionUtil.str2HexStr(methodName + "?" + requestParams);//方法名？+参数（key=value&）
            jb.put("REQUEST_PARM", paramsHex);
            jb.put("UID", SharepreferenceUtil.getUid(mContext));
            jb.put("MAC", "12345");


        } catch (JSONException e) {
            e.printStackTrace();
        }
        mService.postHeaderDataCallback(WebConstant.COMM_FONT, TextUtils.isEmpty(header) ? "" : header, jb.toString(), new IHttpCallbackInterface.Stub() {
            @Override
            public void onSuccess(String result) throws RemoteException {
                CommonResults results = new CommonResults("1", SUCCESS);
                results.addResult(RESULT_JSON, result);
                if (callback != null) {
                    callback.callback(results);
                }
            }

            @Override
            public void onFailed(int errorCode, String errorMsg) throws RemoteException {
                CommonResults results = new CommonResults("-" + errorCode, errorMsg);
                if (callback != null) {
                    callback.callback(results);
                }
            }
        });
        return new CommonResults("1", SUCCESS);
    }
}
